articles

Home / DeveloperSection / Articles / SQL Server Join and Its Types

SQL Server Join and Its Types

Niraj Kumar Mishra2350 21-Aug-2017

SQL JOINS

A JOIN is used to combines rows from two or more tables, based on a related column between them. In other words JOINS are used to fetch data from two or more tables. When you want to perform a SQL statement to attached two or more table’s column then we use SQL JOINS.

Types of Joins:

•          INNER JOIN (simple join)

•          LEFT OUTER JOIN (LEFT JOIN)

•          RIGHT OUTER JOIN (RIGHT JOIN)

•          FULL OUTER JOIN (FULL JOIN)

Let’s see in Examples:

We have 2 Tables ‘Employee’ and ‘Company’:

Employee

SQL Server Join and Its Types

Company

SQL Server Join and Its Types


INNER JOIN (simple join):

If you want to use Inner join then you use INNER JOIN keyword or JOIN.

By using INNER JOIN only those record are fetched that are satisfy the condition in both table.

                                                                SQL Server Join and Its Types

INNER JOIN Syntax
SELECT column name(s) FROM table1 INNER JOIN table2 ON table1.column_name = table2.column_name;

Example:

SQL Server Join and Its Types

LEFT OUTER JOIN (LEFT JOIN):

When you are use LEFT JOIN OR LEFT OUTER JOIN thenit returns all records from the left table and matched record from the right table. It return NULL from the right side, if there is no match.

                                                                                SQL Server Join and Its Types  

LEFT JOIN Syntax
SELECT column name(s) FROM table1 LEFT JOIN table2 ON table1.column_name = table2.column_name;

 

Example:

SQL Server Join and Its Types

RIGHT OUTER JOIN (RIGHT JOIN):

When you are use RIGHT JOIN OR RIGHT OUTER JOIN thenit returns all records from the right table and matched record from the left table. It return NULL from the left side, if there is no match.

 

                                                                                     SQL Server Join and Its Types

RIGHT JOIN Syntax

SELECT column name(s) FROM table1 RIGHT JOIN table2 ON table1.column_name = table2.column_name;
Example:

SQL Server Join and Its Types

FULL OUTER JOIN (FULL JOIN):

When you are use FULL JOIN OR FULL OUTER JOIN thenit returns all records from the Right and Left table with matched and Non-matched with NULL value.

                                                                    

                                                                                     SQL Server Join and Its Types

FULL JOIN Syntax
SELECT column name(s) FROM table1 FULL JOIN table2 ON table1.column_name = table2.column_name;

 

Example:

SQL Server Join and Its Types


I hope you are Understand Join Concept Thank you…











Updated 07-Sep-2019

Leave Comment

Comments

Liked By